package com.lzw.breezeNovel.webApp.controller.novel;

import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.Role;
import com.lzw.breezeNovel.common.result.Result;

import com.lzw.breezeNovel.webApp.service.impl.novel.CustomerServiceimpl;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * @author 清风明月
 * @Package com.lzw.breezeNovel.webApp.controller
 * @date 2025/3/6
 * @description 客服类
 */
@Slf4j
@RestController
@RequestMapping("app/customer")
@SuppressWarnings("all")
public class CustomerController {

    /**
     * 客服服务
     */
    @Autowired
    private CustomerServiceimpl customerService;


    @SneakyThrows
    @GetMapping("/answer")
    public Result<String> getContent(@RequestParam String message) {
        // 创建消息列表
        ArrayList<Message> messages = new ArrayList<>();
        // 添加系统消息
        messages.add(customerService.createMessage(Role.SYSTEM, "你是一个智能助手,可以解决一些常见的问题:"));
        // 添加用户消息到消息列表
        messages.add(customerService.createMessage(Role.USER, message));
        GenerationParam param = customerService.createGenerationParam(messages);
        // 调用生成服务并获取生成结果
        GenerationResult result = customerService.callGenerationWithMessages(param);
        return Result.ok(result.getOutput().getChoices().get(0).getMessage().getContent());
    }

}

